﻿using System;
using System.Diagnostics;
using System.Xml;
using System.Xml.Serialization;

namespace SpectrumAnalyser.Config.Service.Config
{
    public partial class Configuration
    {
        public Configuration()
        {}

        public Configuration(string path)
        {
            var config = ReadConfiguration(path);

            Servers = config.Servers;
            Instances = config.Instances;
        }

         public static Configuration ReadConfiguration(string path)
         {
             try
             {
                 var xmlSerializer = new XmlSerializer(typeof(Configuration));
                 using (var stream = new XmlTextReader(path))
                 {
                     return (Configuration)xmlSerializer.Deserialize(stream);
                 }
             }
             catch (Exception e)
             {
                 Trace.Write(e.ToString());
                 return null;
             }
         }
    }
}